/**
 * Created by ly on 2017/10/12.
 */
var hlValidateUtil = (function () {
  var validateUtil = {
    /*
     *  验证邮箱
     *  @param {String} str
     *  @return {Boolean}
     * */
    validateEmail: function (str) {
      var r = /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

      if (r.test(str)) {
        return true;
      }

      return false;
    },
    /*
     *  验证手机号
     *  @param {String} str
     *  @return {Boolean}
     * */
    validatePhone: function (str) {
      var reg = new RegExp('^1[3|4|5|7|8][0-9]{9}$');
      if (reg.test(str) && str.length === 11) {
        return true;
      }

      return false;
    },
    /*
     *  验证身份证号码
     *  @param {String} str
     *  @return {Boolean}
     * */
    validateIdentityCard: function (str) {
      var reg = new RegExp('^\d{15}$)|(^\d{17}([0-9]|X)$')

      if (reg.test(str)) {
        return true
      }

      return false
    },
    /*
     *  验证输入的字符长度
     *  @param {String} str    验证的字符
     *  @param {String} length  验证的长度
     *  @return {Boolean}
     * */
    validateLength: function (str, length) {
      var realLength = 0, len = str.length, charCode = -1;
      if (len > length) {
        return false
      }
      return true
    },
    /*
     *   验证输入内容是否是中英文
     *   @param {String} 验证字符串
     *   @return {Boolean}
     * */
    validateChEn: function (str) {
      var reg = new RegExp('^([\u4E00-\uFA29]*[a-z]*[A-Z]*)+$')
      if (reg.test(str)) {
        return true
      }
      return false
    },
    /*
     *   验证输入内容是否为空
     *   @param {String} 验证字符串
     *   @return {Boolean}
     * */
    validateIsEmpty: function (str) {
      var length = str.length
      if (length !== 0) {
        return true
      }
      return false
    }
  }
  return validateUtil
}());
